﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using Frame.Lib.Core.Dict;
using Frame.Lib.Utilities;
using Frame.Lib.Web;
using Frame.Lib.Common;


public partial class Common_Dict_List :PageList
{
    private DictBO dict = new DictBO();
    private string strOrders;
    private int ItemID
    {
        get
        {
            return int.Parse(StrUtil.DecryptUrl(Request["ItemID"]));
        }
    }

    private string ItemName
    {
        get
        {
            return Request.QueryString["ItemName"];
        }
    }
    PagerSortSetting setting;

   
    protected void Page_Load(object sender, EventArgs e)
    {

        setting = this.Footer1.InitPager(new BindViewHandler(BindView));
       
        if (!IsPostBack)
        {
            BindView();
        }
        AddAttr();
        base.InitSelectID(hidSelectIDs);
        strOrders = hidOrders.Value;
        hidOrders.Value = "";
        lblTitle.Text = this.ItemName;

        JSUtil.SetTableHeight("list", 140); 
    }
    private void AddAttr()
    {
        JSUtil.DelConfirm(btnDelete, "字典");
        JSUtil.ShowForm(lnkAdd,"增加", null, GlobalVar.WebCurrPath + "Edit.aspx?ItemID=" + ItemID, 300, 203);
        JSUtil.ClickBtn(lnkDelete, btnDelete);
        JSUtil.ClickBtn(lnkSaveOrders, btnSaveOrders);
    }
    private void BindView()
    {
        LVUtil.Init(lv, lvHeader);
        IEnumerable<DictInfo> dt = dict.GetList(ItemID,setting);
        lv.DataSource = dt;
        lv.DataKeyNames = new string[] { "ID" };
        lv.DataBind();
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        if (strSelectIDs == "")
        {
            return;
        }
        List<int> lstSelectIDs = StrUtil.SplitToInt(strSelectIDs);
        dict.Delete(lstSelectIDs);
        BindView();
    }
    protected void btnSaveSequence_Click(object sender, EventArgs e)
    {
        List<int> ids = new List<int>();
        List<int> orders = new List<int>();
        StrUtil.SplitIDOrders(ids, orders, strOrders);
        dict.SaveOrders(ids, orders);
        BindView();
    }
   
    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        BindView();
    }

    protected void lv_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            LVUtil.SetEdit(sender, e, 300, 203);
        }
    }
}
